﻿using System;
using DDotNet.ORM.ORMapping.Attribute;
using DDotNet.ORM.ORMapping.Attribute.DirectAccess;
using DDotNet.ORM.ORMapping.OREntity;
using DDotNet.ORM.ORMapping.Validation;

namespace DDotNet.Web.UI.AutomatedPageBuilder.TestApplication.Entities
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable()]
    [DBMapping("MainDB")]
    [DirectEntityMapping("tb_User", AllowDelete = true, AllowInsert = true, AllowUpdate = true)]
    public sealed class User : BusinessEntityBase
    {
        #region Construtor

        public User()
        {
        }

        #endregion

        #region Fields and Properties

        private string _Login;

        /// <summary>
        ///
        /// </summary>
        [PropertyMapping("Login")]
        public string Login
        {
            get { return this._Login; }
            set
            {
                this._Login = value;
                base.MarkDirty("Login");
            }
        }

        private string _Password;

        /// <summary>
        ///
        /// </summary>
        [PropertyMapping("Password")]
        public string Password
        {
            get { return this._Password; }
            set
            {
                this._Password = value;
                base.MarkDirty("Password");
            }
        }


        private string _FullName;

        /// <summary>
        ///
        /// </summary>
        [PropertyMapping("FullName")]
        public string FullName
        {
            get { return this._FullName; }
            set
            {
                this._FullName = value;
                base.MarkDirty("FullName");
            }
        }

        private int _IDUser;

        /// <summary>
        ///
        /// </summary>
        [EntityPrimaryKey(true)]
        [PropertyMapping("IDUser")]
        public int IDUser
        {
            get { return this._IDUser; }
            set
            {
                this._IDUser = value;
                base.MarkDirty("IDUser");
            }
        }


        private SexEnumerator _Sex;

        /// <summary>
        ///
        /// </summary>
        [PropertyMapping("Sex")]
        public SexEnumerator Sex
        {
            get { return this._Sex; }
            set
            {
                this._Sex = value;
                base.MarkDirty("Sex");
            }
        }

        #endregion

        /// <summary>
        /// Adiciona as Regras de Validação na Entidade
        /// </summary>
        protected override void AddValidationRules()
        {
            this.Validations.Add(new ValidationRule(
                                     "FullName_NotNull",
                                     "FullName",
                                     "O Nome do Usuário é Requirido",
                                     CommonRules.Instance.StringRequired));

            this.Validations.Add(new ValidationRule(
                                     "FullName_MinValue",
                                     "FullName",
                                     "O Nome do Usuário Deve ter no Mínimo 1 Caracter",
                                     CommonRules.Instance.StringMinLength,
                                     new StringMinLengthArgs(1)));

            this.Validations.Add(new ValidationRule(
                                     "FullName_MaxValue",
                                     "FullName",
                                     "O Nome do Usuário Deve ter no Máximo 255 Caracteres",
                                     CommonRules.Instance.StringMaxLength,
                                     new StringMaxLengthArgs(255)));


            this.Validations.Add(new ValidationRule(
                                     "Password_NotNull",
                                     "Password",
                                     "O Password do Usuário é Requirido",
                                     CommonRules.Instance.StringRequired));
        }
    }
}